from flask import Flask, request, jsonify
import requests
from module import Task
from extension import db



# 替换为你的百度地图API密钥
BAIDU_MAPS_API_KEY = 'Bd7EoubC1VQRBDXuGJKGsdH0UL1ZeiVo'

police_pos = [40.757942586416995, -73.96969536490462]
test_pos = [40.754313408181034, -73.97646529118015]

def short_distance():
    # 接口地址
    url = "https://api.map.baidu.com/directionlite/v1/walking"
    #纬 经
    #lat 纬度

    params = {
        # "origin":    "39.957902,116.34974",
        # "destination":    "39.952935,116.353941",
        "origin":    "40.757942586416995,-73.96969536490462",
        "destination":    "40.754313408181034,-73.97646529118015",
        "ak":       BAIDU_MAPS_API_KEY,

    }

    response = requests.get(url=url, params=params)
    if response:
        return response.json()

def short_distance2(toWaypoint):
    import requests

    myAPIKey = "24d1e305770e495e8cb7bc6b8f729c20"
    tasks=Task.query.filter_by()
    fromWaypoint = [40.75794, -73.96969]  # 纬度，经度
    #toWaypoint = [40.75431, -73.97646]  # 纬度，经度
    url = f"https://api.geoapify.com/v1/routing?waypoints={fromWaypoint[0]},{fromWaypoint[1]}|{toWaypoint[0]},{toWaypoint[1]}&mode=drive&details=instruction_details&apiKey={myAPIKey}"

    response = requests.get(url)
    if response.status_code == 200:
        result = response.json()
        distance = result['features'][0]['properties']['distance']
        #print(distance)
        return distance
    else:
        pass